package com.example.administrator.dc.Activity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.example.administrator.dc.Bean.Collectlistresult;
import com.example.administrator.dc.Bean.DataEntity;
import com.example.administrator.dc.Bean.Dataphoto;
import com.example.administrator.dc.Bean.Myphoto;
import com.example.administrator.dc.R;
import com.example.administrator.dc.Service.CollectService;
import com.example.administrator.dc.Service.UserService;
import com.example.administrator.dc.adapter.CollectlistAdapter;
import com.example.administrator.dc.adapter.Photolistadapter;
import com.example.administrator.dc.model.Contants;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class PhotoImage extends BaseActivity {
    private RecyclerView photorecycle;
    public List<Dataphoto> photolist;
    private Photolistadapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_photo_image);
        init();
        connect();
    }
    private  void  init(){
        photorecycle= (RecyclerView) findViewById(R.id.recyclerphoto);

    }
    private  void  connect(){
        SharedPreferences sp = getApplication().getSharedPreferences("UserInfo", getApplication().MODE_PRIVATE);
        String userid =sp.getString("user_id", null);
        Retrofit retrofit= new Retrofit.Builder().baseUrl(Contants.BASE_URL1).
                addConverterFactory(GsonConverterFactory.create()).build();
        UserService service=retrofit.create(UserService.class);
        Call<Myphoto> call= service.myphoto(userid);
        call.enqueue(new Callback<Myphoto>() {
            @Override
            public void onResponse(Call<Myphoto> call, Response<Myphoto> response) {
                if(response.body().getStatus()==1){
                    photolist=response.body().getData();
                    adapter=new Photolistadapter(PhotoImage.this,photolist);
                    LinearLayoutManager layoutManager=new LinearLayoutManager(PhotoImage.this);
                    //  layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                    GridLayoutManager gm = new GridLayoutManager(PhotoImage.this,2);
                    // 网格是的list布局   2列
                    // recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));
                    photorecycle.setLayoutManager(gm);
                    // header.attachTo(recyclerView);
                    //  recyclerView.setLayoutManager(layoutManager);
                    photorecycle.setAdapter(adapter);
                    photorecycle.setItemAnimator(new DefaultItemAnimator());



                }

            }

            @Override
            public void onFailure(Call<Myphoto> call, Throwable t) {

            }
        });




    }


}
